package com.ruoyi.web.controller.health;

import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.health.domain.HealthClock;
import com.ruoyi.health.service.IHealthClockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 打卡信息Controller
 *
 * @author rockvan
 * @date 2023-04-10
 */
@Api("打卡信息管理")
@RestController
@RequestMapping("/health/healthclockinfo")
public class HealthClockController extends BaseController
{
    @Autowired
    private IHealthClockService healthClockService;

    /**
     * 查询打卡信息列表
     */
    @ApiOperation("获取打卡信息列表")
    @PreAuthorize("@ss.hasPermi('health:healthclockinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(HealthClock healthClock)
    {
        startPage();
        List<HealthClock> list = healthClockService.selectHealthClockList(healthClock);
        return getDataTable(list);
    }

    /**
     * 导出打卡信息列表
     */
    @ApiOperation("导出打卡信息列表")
    @PreAuthorize("@ss.hasPermi('health:healthclockinfo:export')")
    @Log(title = "打卡信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HealthClock healthClock)
    {
        List<HealthClock> list = healthClockService.selectHealthClockList(healthClock);
        ExcelUtil<HealthClock> util = new ExcelUtil<HealthClock>(HealthClock.class);
        util.exportExcel(response, list, "打卡信息数据");
    }

    /**
     * 获取打卡信息详细信息
     */
    @ApiOperation("获取打卡信息详细信息")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermi('health:healthclockinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(healthClockService.selectHealthClockById(id));
    }

    /**
     * 新增打卡信息
     */
    @ApiOperation("新增打卡信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "编号", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "username", value = "姓名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "healthType", value = "健康状态", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "temperature", value = "体温", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
            @ApiImplicitParam(name = "middleHigh", value = "风险地区", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "diagnosis", value = "确诊", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "returnInfo", value = "境外返回", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "address", value = "打卡位置", dataType = "String", dataTypeClass = String.class),
    })
    @PreAuthorize("@ss.hasPermi('health:healthclockinfo:add')")
    @Log(title = "打卡信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthClock healthClock)
    {
        healthClock.setUsername(getUsername());
        return toAjax(healthClockService.insertHealthClock(healthClock));
    }

    /**
     * 修改打卡信息
     */
    @ApiOperation("更改打卡信息")
    @PreAuthorize("@ss.hasPermi('health:healthclockinfo:edit')")
    @Log(title = "打卡信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthClock healthClock)
    {
        return toAjax(healthClockService.updateHealthClock(healthClock));
    }

    /**
     * 删除打卡信息
     */
    @ApiOperation("删除打卡信息")
    @ApiImplicitParam(name = "ids", value = "编号", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermi('health:healthclockinfo:remove')")
    @Log(title = "打卡信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(healthClockService.deleteHealthClockByIds(ids));
    }
}
